
#include <stdio.h>
#include <math.h>
#include "Index.h"


	Index::Index()
	{

	}
	//constructors
	Index::Index(bool v0, bool v1, bool v2, bool v3, bool v4, bool v5, bool v6, bool v7)
	{
		_index[0] = v0;
		_index[1] = v1;
		_index[2] = v2;
		_index[3] = v3;
		_index[4] = v4;
		_index[5] = v5;
		_index[6] = v6;
		_index[7] = v7;
	}

	bool Index::compareIndex(Index & index2)
	{
		for(int i =0; i < 8; i++)
			if(_index[i] != index2.getValue(i))
				return false;

		return true;
	}

	Index Index::rotateIndex(int rotx, int roty, int rotz)
	{
		Index newIndex (_index[0],_index[1],_index[2],_index[3],_index[4],_index[5],_index[6],_index[7]);
		Index tmpIndex (_index[0],_index[1],_index[2],_index[3],_index[4],_index[5],_index[6],_index[7]);
				//rotacion respecto eje x
				for(int i = 0; i < rotx; i++)
				{
					newIndex.setIndex(0, tmpIndex.getValue(3));
					newIndex.setIndex(1, tmpIndex.getValue(2));
					newIndex.setIndex(2, tmpIndex.getValue(6));
					newIndex.setIndex(3, tmpIndex.getValue(7));
					newIndex.setIndex(4,  tmpIndex.getValue(0));
					newIndex.setIndex(5, tmpIndex.getValue(1));
					newIndex.setIndex(6, tmpIndex.getValue(5));
					newIndex.setIndex(7, tmpIndex.getValue(4));

					tmpIndex = newIndex;
				}
				//rotacion respecto eje y
				for(int i = 0; i < roty; i++)
				{
					newIndex.setIndex(0, tmpIndex.getValue(1));
					newIndex.setIndex(1, tmpIndex.getValue(5));
					newIndex.setIndex(2, tmpIndex.getValue(6));
					newIndex.setIndex(3, tmpIndex.getValue(2));
					newIndex.setIndex(4, tmpIndex.getValue(0));
					newIndex.setIndex(5, tmpIndex.getValue(4));
					newIndex.setIndex(6, tmpIndex.getValue(7));
					newIndex.setIndex(7, tmpIndex.getValue(3));

					tmpIndex = newIndex;

				}
				//rotacion respecto eje z
				for(int i = 0; i < rotz; i++)
				{
					newIndex.setIndex(0, tmpIndex.getValue(3));
					newIndex.setIndex(1,tmpIndex.getValue(0));
					newIndex.setIndex(2, tmpIndex.getValue(1));
					newIndex.setIndex(3, tmpIndex.getValue(2));
					newIndex.setIndex(4, tmpIndex.getValue(7));
					newIndex.setIndex(5, tmpIndex.getValue(4));
					newIndex.setIndex(6, tmpIndex.getValue(5));
					newIndex.setIndex(7, tmpIndex.getValue(6));

					tmpIndex = newIndex;

				}
				return newIndex;
	}

	void Index::setIndex(int i, bool value)
	{
		_index[i] = value;
	}

	bool Index::getValue(int i)
	{
		return _index[i];
	}

	Index  Index::operator=( Index other)
	{
		for(int i = 0; i < 8; i ++)
			_index[i] = other.getValue(i);

		return *this;
	}

	Index Index::complementario()
	{
		Index ind;
		for (int i = 0; i < 8; i++)
			_index[i]==true?ind.setIndex(i,false):ind.setIndex(i, true);

		return ind;
	}

	bool Index::esCasoBase(int i, std::vector<Index> & casosBase)
	{
		return compareIndex(casosBase.at(i));
	}

